<template>
  <div class="goods-item" @click="goodsItemClick(goodsId)">
    <img v-lazy="imageUrl" @load="imgLoad">
    <div class="goods-info">
      <p>{{goods.title}}</p>
      <span class="price">{{goods.price | formatPrice}}</span>
      <span class="collect">{{goods.cfav}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "GoodsListItem",
    props: {
      goods: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    computed: {
      imageUrl() {
        return this.goods.image || this.goods.show.img
      },
      goodsId() {
        return this.goods.item_id || this.goods.iid
      }
    },
    methods: {
      imgLoad() {
        this.$bus.$emit('itemImgLoad')
      },
      goodsItemClick(goodsId) {
        this.$router.push('/detail/' + goodsId)
      }
    }
  }
</script>

<style scoped>
  .goods-item {
    padding-bottom: 50px;
    position: relative;
    width: 46%;
  }

  .goods-item img {
    width: 100%;
    border-radius: 5px;
  }

  .goods-info {
    font-size: 14px;
    position: absolute;
    left: 0;
    right: 0;
    overflow: hidden;
  }

  .goods-info p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
    margin-top: 0px;
  }

  .goods-info .price {
    color: var(--color-high-text);
    margin-right: 20px;
    font-size: 18px;
    font-weight: bolder;
  }

  .goods-info .collect {
    position: relative;
    float: right;
    margin-right: 14px;
  }

  .goods-info .collect:after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
    /*content:url("~assets/img/common/collect.svg");*/
  }
</style>
